package com.scuec.groupfive.mapper;

import com.scuec.groupfive.entity.Post;
import com.scuec.groupfive.entity.PostComment;
import com.scuec.groupfive.entity.PostFavorite;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserPostMapper {

    @Select("SELECT * FROM post_favorites WHERE user_id = #{userId}")
    List<PostFavorite> selectFavoritesByUserId(@Param("userId") Long userId);

    @Select("SELECT * FROM posts WHERE post_id = #{postId}")
    Post selectPostById(@Param("postId") Long postId);

    @Delete("DELETE FROM post_favorites WHERE favorite_id = #{favoriteId}")
    int deleteFavorite(@Param("favoriteId") Long favoriteId);

    // 新增：根据帖子ID查询所有评论
    @Select("SELECT " +
            "comment_id, post_id, user_id, content, " +
            "parent_id, status, created_at, updated_at " +
            "FROM post_comments " +
            "WHERE post_id = #{postId}")
    @Results({
            @Result(property = "commentId", column = "comment_id"),
            @Result(property = "postId", column = "post_id"),
            @Result(property = "userId", column = "user_id"),
            @Result(property = "parentId", column = "parent_id"),
            @Result(property = "createdAt", column = "created_at"),
            @Result(property = "updatedAt", column = "updated_at")
    })
    List<PostComment> selectCommentsByPostId(@Param("postId") Long postId);
}